package com.lianxian.xindong.home.mvp.ui.weight.douyin;

import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.android.library.YLCircleImageView;
import com.bumptech.glide.Glide;
import com.lianxian.xindong.home.R;
import com.lianxian.xindong.home.mvp.model.entity.VideoUserBean;

import java.util.List;

import butterknife.BindView;

/**
 * @author: Hexingbo
 * @date: 2023/7/3
 * @description：
 */
public class ListVideoAdapter extends BaseRecAdapter<VideoUserBean, VideoViewHolder> {

    private MyVideoPlayer mVideoPlayer;

    public void setVideoPlayer(MyVideoPlayer videoPlayer) {
        mVideoPlayer = videoPlayer;
    }


    public ListVideoAdapter(List<VideoUserBean> list) {
        super(list);
    }

    @Override
    public void onHolder(VideoViewHolder holder, VideoUserBean bean, int position) {
        ViewGroup.LayoutParams layoutParams = holder.itemView.getLayoutParams();
        layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT;

        holder.mp_video.setUp(bean.getVideoUrl(), bean.getNice(), MyVideoPlayer.STATE_NORMAL);
        if (position == 0) {
            setVideoPlayer(holder.mp_video);
            holder.mp_video.startVideo();
        }
        Glide.with(context).load(bean.getVideoUrl()).into(holder.mp_video.thumbImageView);
        Glide.with(context).load(bean.getHeadUrl()).into(holder.iv_head);
        holder.tv_title.setText(bean.getNice());
        holder.tv_des.setText(bean.getDes());
        holder.iv_care.setSelected(bean.isCare());
        holder.tv_zan.setSelected(bean.isZan());

        View.OnClickListener onClickListener = new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (getItemClickListener() != null) {
                    getItemClickListener().onItemClick(ListVideoAdapter.this, v, holder.getLayoutPosition());
                }
            }
        };
        holder.iv_head.setOnClickListener(onClickListener);
        holder.iv_care.setOnClickListener(onClickListener);
        holder.tv_zan.setOnClickListener(onClickListener);
        holder.tv_msg_drop.setOnClickListener(onClickListener);
        holder.iv_msg_hi.setOnClickListener(onClickListener);
        holder.iv_liwu.setOnClickListener(onClickListener);
    }

    @Override
    public VideoViewHolder onCreateHolder() {
        return new VideoViewHolder(getViewByRes(R.layout.item_video_player));

    }

    public void onPausePlay() {
        if (mVideoPlayer != null) {
            mVideoPlayer.onPausePlay();
        }
    }

    public void onStartPlay() {
        if (mVideoPlayer != null) {
            mVideoPlayer.onStartPlay();
        }
    }
}
